#!/bin/sh

if [ "$1" = "autoconf" ]; then
	if which apcaccess > /dev/null; then
		echo yes
		exit 0
	else
		echo no
		exit 0
	fi
fi

if [ "$1" = "config" ]; then
	cat <<EOF
graph_title UPS Capacity Percentage
graph_category sensors
graph_vlabel %
graph_args --base 1000 -l 0
graph_info UPS Percentages
loadpct.label Load capacity
bcharge.label Battery capacity charge
EOF
	exit 0
fi

apcaccess -u | awk '
/:/ {
	a[tolower($1)] = $3
}
END {
	print "loadpct.value", a["loadpct"]
	print "bcharge.value", a["bcharge"]
}
'
